package com.siyoumi.util;

import org.slf4j.MDC;

//日志赋值 请求类型 请求ID
public class LogMdc {
    private static final String REQUEST_ID_KEY = "request_id";

    /**
     * 请求ID
     *
     * @param id
     */
    public static void setRequestId(String id) {
        if (XStr.isNullOrEmpty(id)) {
            id = XApp.random(100000, 999999) + "";
        }
        MDC.put(REQUEST_ID_KEY, id);
    }

    public static void setRequestId() {
        setRequestId(null);
    }

    public static String getRequestId() {
        return MDC.get(REQUEST_ID_KEY);
    }
}